package com.xiongwei.command;

/**
 * 遥控器
 * @author XiongWei
 * @date 2024/1/28
 */
public class Controller {

    private Command undoCommand;
    Command[] onCommands;
    Command[] offCommands;


    /**
     * 设置命令
     */
    public Controller() {
        onCommands = new Command[5];
        offCommands = new Command[5];

        for (int i = 0; i < 5; i++) {
            onCommands[i] = new NoCommand();
            offCommands[i] = new NoCommand();
        }
    }

    public void setCommand(int slot, Command onCommand, Command offCommand) {
        onCommands[slot] = onCommand;
        offCommands[slot] = offCommand;
    }

    public void on(int slot) {
        onCommands[slot].execute();
    }

    public void off(int slot) {
        offCommands[slot].execute();
    }

    public void undo(int slot) {
        onCommands[slot].undo();
    }

}
